package cn.myframe.service.sys.impl;

import cn.myframe.dao.sys.SysInfoDao;
import cn.myframe.entity.sys.SysInfoEntity;
import cn.myframe.service.sys.SysInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("sysInfoService")
public class SysInfoServiceImpl implements SysInfoService {
	@Autowired
	private SysInfoDao sysInfoDao;
	
	@Override
	public SysInfoEntity queryObject(Long id){
		return sysInfoDao.queryObject(id);
	}
	
	@Override
	public List<SysInfoEntity> queryList(Map<String, Object> map){
		return sysInfoDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return sysInfoDao.queryTotal(map);
	}
	
	@Override
	public void save(SysInfoEntity sysInfo){
		sysInfoDao.save(sysInfo);
	}
	
	@Override
	public void update(SysInfoEntity sysInfo){
		sysInfoDao.update(sysInfo);
	}
	
	@Override
	public void delete(Long id){
		sysInfoDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		sysInfoDao.deleteBatch(ids);
	}
	
	@Override
	public int checkExist(String id, String name) {
		return sysInfoDao.checkExist(id, name);
	}
	
	@Override
	public int updateStatus(Long[] ids, Integer status) {
		return sysInfoDao.updateStatus(ids, status);
	}
	
	@Override
	public List<SysInfoEntity> queryInfoList(Map<String, Object> map){
		return sysInfoDao.queryInfoList(map);
	}
	@Override
	public int queryInfoCount(Long uerId,Long companyId,List<Long> list){
		return sysInfoDao.queryInfoCount(uerId,companyId,list);
	}
	
	@Override
	public int queryAdminInfoCount(Long uerId){
		return sysInfoDao.queryAdminInfoCount(uerId);
	}
	
	public int queryUserTotal(Map<String, Object> map){
		return sysInfoDao.queryUserTotal(map);
	}
	
	public List<SysInfoEntity> selectSysInfos(Long[] ids){
		return sysInfoDao.selectSysInfos(ids);
	}

	/**
	 * 发送系统消息
	 * @param title
	 * @param content
	 * @param userId
	 * @return
	 */
	@Override
	@Transactional(readOnly = false)
	public void sendSysInfo(String title, String content, Long userId) {
		SysInfoEntity sysInfo = new SysInfoEntity();
		sysInfo.setInfoType(SysInfoEntity.TYPE_SYS);
		sysInfo.setInfoContent(content);
		sysInfo.setInfoTitle(title);
		sysInfo.setStatus(SysInfoEntity.STATUS_NOT_READ);
		sysInfo.setCreateBy(userId);
		sysInfo.setUpdateBy(userId);
		sysInfo.setCreateTime(new Date());
		sysInfo.setUpdateTime(new Date());
		sysInfoDao.save(sysInfo);
	}

}
